
#include <linux/version.h>
#include <linux/input.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#include "spi.h"
#include "ReceiveInfo.h"
#include "Input_Irkeymap.h"
#include "MenuSystem.h"
#include "IrControl.h"
#include "Menu/Tool/frame.h"
#include "BF533/TouchPanel.h"
//Bill modify
#include <errno.h>
#include "msgtool.h"
#include "PowerOff.h"

extern		int NavigationInitFlag;
extern		pid_t NavigationPID;
extern		pid_t UIPID;
extern int TS_KX; ////20080217
extern int TS_KY;

static int	ReadInfoKey = NO_INFO;	// last virtual key
unsigned char read_info_data[20] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00};//{0};0x57 is 87D.that's 87.5
unsigned char navi_status = 0;
unsigned char mute_status = 0;//mute is 1,demute is 2;
unsigned char navi_run = 0;//navi close is 0,navi active is 1;
TRect		MuteInfoPos= {620,20,710,100};
unsigned char rece_handle; //= 1 is need handle.
int 		Last_ID = 0;
int 		BeepFlag = 0;




int dev_ReceiveBuf( void )
{
	int receive_data;
	receive_data = ReadInfoKey;
	ReadInfoKey = NO_INFO;
	
	return receive_data;
}


int dev_ReceiveInfoRead(void)
{
	int rc;
	static int i;
	
	if (i>5)
		{
			i=0;
		}
		else
			i++;
	if (!dev_SPIRead(read_info_data))
		{
//		printf ("read failure!\n");	
  		rc = -1;		
		}
	else
		{
			//printf ("read data!\n");	
			if (read_info_data[0] == 0xe1)
				{
					//ReadInfoKey = IRC_READ_INFO;
					rc = 0;
				}	
				else
					rc = 1;							
			//ReadInfoKey = IRC_READ_INFO;//suppose it is receive data from MCU. for test becarefull
		}
		return rc;
	
}


int rece_data_chk (void)
{
	unsigned char len,i;
	unsigned char chksum=0;	
		
	
	if (read_info_data[0] != 0xe1)
		return -1;
	
//	if ( !MenuMainFirstFlag)
//		MenuMainFirstFlag = 1; /////20080228
		
	len = read_info_data[1];
	for (i=0; i<len+1; i++)
	{
			chksum =(unsigned char) (chksum + read_info_data[i]);		
	}
	if ( chksum != read_info_data [len+1])
		return -1;
	else
		return 0;
		
		
}
/*****************************
function:ReceiveData_handle
 for pthread call,first handle 
 receive info.
 return:
  0: successful
  1: need menu handle
  -1:failure
*****************************/
int ReceiveData_handle(void)
{	


			return 0;
}


